<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        .box {
            height: 500px;
            width: 500px;
            position: relative;
            left: 50%;
            top: 50%;
            transform: translateX(-50%);
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
        }

        .box .title {
            text-align: center;
            font-weight: 700;
            position: absolute;
            top: 50px;
        }

        .box .block input {
            width: 200px;
            height: 30px;
            margin: 10px 0;
            padding-left: 10px;
            outline: none;
            border-radius: 5px;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="title">
            注册页面
        </div>
        <div class="block">
            <input type="text" placeholder="请输入用户名">
        </div>
        <div class="block">
            <input type="password" placeholder="请输入密码">
        </div>
        <select>
            <option value="男">男</option>
            <option value="女">女</option>
        </select>
        <div class="block">
            <input type="text" placeholder="请输入年龄">
        </div>
        <div class="block">
            <input type="text" placeholder="请输入手机号">
        </div>
        <div class="block">
            <input type="button" value="注册">
        </div>
    </div>
   
</body>

</html>
<script src="promise-ajax函数.js"></script>
<script>
    let inp = document.querySelectorAll('input')
    inp[4].addEventListener('click', function () {

        if (inp[0].value && inp[1].value) {
            if (/^\d{9}$/.test(inp[0].value) && /^\d{4}$/.test(inp[1].value)) {
                ajax('post', 'https://yantianfeng.com/api/register', {
                    username: inp[0].value,
                    password: inp[1].value,
                    sex: '男',
                    age: inp[2].value,
                    phone: inp[3].value
            }).then((data)=>{
                alert(data.msg)
            })
            }else{
                alert('请输入正确的用户名/密码')
            }
        } else {
            alert('请输入用户名/密码')
        }
    })
</script>